package Aspect;

import Controller.AppRecordsController;
import POJO.AppRecords;
import POJO.Model.ResponseModel;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Aspect
@Component
public class AppRecordsAspect {
    @Resource
    ResponseModel responseModel;

    @Around(value = "bean(AppRecordsController) &&execution(* Controller.AppRecordsController.insertAppRecords(..))&& args(appRecords)", argNames ="proceedingJoinPoint,appRecords")
    public ResponseModel AppRecordsCheck(ProceedingJoinPoint proceedingJoinPoint, AppRecords appRecords) throws Throwable
    {
        responseModel.setNull();
        boolean mac= appRecords.getAppDeviceMac()==null;
        boolean record =appRecords.getPatientId()==0;
        boolean de=appRecords.getDepartment()==null;
        boolean bedno=appRecords.getBedNo()==null;
        boolean sp=appRecords.getSp()==0;
        boolean dbp=appRecords.getDbp()==0;
        boolean ah=appRecords.getAh()==0;
        boolean br=appRecords.getBr()==0;
        boolean hr=appRecords.getHr()==0;
        boolean pr=appRecords.getPr()==0;
        boolean bo=appRecords.getBo()==0;
        boolean time=appRecords.getTimeStamp()==null;

        boolean all=mac&record&de&bedno&sp&dbp&ah&br&hr&pr&bo&time;

        if (all)
        {
            responseModel.setCode(219);
            responseModel.setMsg("未填写完整");

        }
        else {
            proceedingJoinPoint.proceed(new Object[]{appRecords});
            responseModel.setCode(200);
            responseModel.setMsg("成功");
        }
        return  responseModel;
    }
}
